package cn.edu.scau.cmi.wujiaxian.exercise8;

class Goods {
	boolean isDanger;
	String name;
	public Goods(String name) {
		this.name = name;
	}
	public void setIsDanger(boolean isDanger) {
		this.isDanger = isDanger;
	}
	public boolean isDanger() {
		return isDanger;
	}
	public String getName() {
		return name;
	}
}

@SuppressWarnings("serial")
class Danger1Exception extends Exception {
	String message;
	public Danger1Exception() {
		message = "危险品";
	}
	public void toShow() {
		System.out.print(message + " ");
	}
}

class Machine {
	public void checkBag(Goods goods) throws Danger1Exception {
		if (goods.isDanger()) {
			Danger1Exception danger = new Danger1Exception();
			throw danger;
		}
	}
}

public class Check {
	public static void main(String[] args) {
		Machine machine = new Machine();
		Goods apple = new Goods("苹果");
		apple.setIsDanger(false);
		Goods explosive = new Goods("炸药");
		explosive.setIsDanger(true);
		try {
			machine.checkBag(explosive);
			System.out.println(explosive.getName() + "检查通过");
		} catch (Danger1Exception e) {
			e.toShow();
			System.out.println(explosive.getName() + "被禁止");
		}
		try {
			machine.checkBag(apple);
			System.out.println(apple.getName() + "检查通过");
		} catch (Danger1Exception e) {
			e.toShow();
			System.out.println(apple.getName() + "被禁止");
		}
	}
}
